export default {
    namespaced: true,
    state: {
        //是否打开歌词界面
        isOnPlay: sessionStorage.getItem('isOnPlay') ? sessionStorage.getItem('isOnPlay') : 'false',
        // 歌手信息
        singer: {},
        //播放状态
        isPlaying: sessionStorage.getItem('isPlaying') ? sessionStorage.getItem('isPlaying') : 'false',
        //当前歌单id
        songListId: "",
        //播放列表
        playList: sessionStorage.getItem('playList') ? JSON.parse(sessionStorage.getItem('playList')) : [],
        //历史播放列表
        hisMusicList: [],
        //当前播放歌曲url
        musicUrl: sessionStorage.getItem('musicUrl') ? sessionStorage.getItem('musicUrl') : "",
        //当前播放歌曲详情
        musicDetail: sessionStorage.getItem('musicDetail') ? JSON.parse(sessionStorage.getItem('musicDetail')) : {
            name: '暂无',
            al: { picUrl: '' },
            ar: [{ name: '暂无' }]
        },
        //当前播放歌曲id
        songId: sessionStorage.getItem('songId') ? sessionStorage.getItem('songId') : "",
        //当前歌曲进度
        nowDuration: 0,
        //当前播放模式
        playOrder: sessionStorage.getItem('playOrder') ? sessionStorage.getItem('playOrder') * 1 : 0,
        //播放过的歌曲id
        hasPlayList: sessionStorage.getItem('hasPlayList') ? JSON.parse(sessionStorage.getItem('hasPlayList')) : [],
        //播放时间
        currentTime: sessionStorage.getItem('currentTime') ? sessionStorage.getItem('currentTime') * 1 : '00:00',
        // 加载状态
        isLoading: false,
        //歌曲时长
        durationTime: sessionStorage.getItem('durationTime') ? sessionStorage.getItem('durationTime') : '00:00',
        //当前播放音量
        volumeVal: sessionStorage.getItem('volumeVal') ? sessionStorage.getItem('volumeVal') * 1 : 50,
        //歌曲时长秒数
        maxTime: sessionStorage.getItem('maxTime') ? sessionStorage.getItem('maxTime') * 1 : 0,
        //当前播放进度秒数
        sliderTime: sessionStorage.getItem('sliderTime') ? sessionStorage.getItem('sliderTime') * 1 : 0,
        //保存列表索引
        listIndex: sessionStorage.getItem('listIndex') ? sessionStorage.getItem('listIndex') * 1 : 0,
        // 是否喜欢音乐
        isLike: sessionStorage.getItem('isLike') ? sessionStorage.getItem('isLike') : "false"

    },
    mutations: {
        //保存isLike
        saveIsLike(state, isLike) {
            state.isLike = isLike
        },
        //保存列表索引
        saveListIndex(state, listIndex) {
            state.listIndex = listIndex
        },
        //保存歌词界面开关
        saveIsOnPlay(state, isOnPlay) {
            state.isOnPlay = isOnPlay;
        },
        // 保存播放状态
        saveIsPlaying(state, isPlaying) {
            state.isPlaying = isPlaying;
        },
        //保存当前歌单id
        saveSongListId(state, songListId) {
            state.songListId = songListId;
        },
        //保存当前播放歌单列表
        savePlayList(state, playList) {
            state.playList = playList;
        },
        // 添加当前播放列表
        unshiftPlayList(state, playList) {
            state.playList.unshift(playList);
        },
        // 添加历史记录播放列表
        unshiftHisMusicList(state, hisMusicList) {
            state.hisMusicList.unshift(hisMusicList);
        },

        pushPlayList(state, playList) {
            console.log(playList);
            // state.hasPlayList:[...playList]
            [...state.playList, ...playList];
        },
        // 添加历史记录播放列表
        unshiftHisMusicList(state, hisMusicList) {
            state.hisMusicList.unshift(hisMusicList);
        },
        // 保存当前正在播放的音乐路径
        saveMusicUrl(state, musicUrl) {
            state.musicUrl = musicUrl
        },
        // 保存当前正在播放的音乐细节
        saveMusicDetail(state, musicDetail) {
            state.musicDetail = musicDetail
        },
        // 保存当前正在播放的歌曲id
        saveSongId(state, songId) {
            state.songId = songId
        },
        //保存播放歌曲信息
        saveHasPlayList(state, songId) {
            // console.log(state.hasPlayList);
            state.hasPlayList.push(songId)
            sessionStorage.setItem('hasPlayList', JSON.stringify(state.hasPlayList))
        },
        //保存播放时间
        saveCurrentTime(state, currentTime) {
            state.currentTime = currentTime
        },
        //保存当前歌曲播放秒数
        saveSliderTime(state, sliderTime) {
            state.sliderTime = sliderTime
        },
        // 修改当前加载状态
        changeIsLoading(state, isLoading) {
            state.isLoading = isLoading
        },
        //保存歌曲时长
        saveDurationTime(state, durationTime) {
            state.durationTime = durationTime
        },
        //保存当前播放音量
        saveVolumeVal(state, volumeVal) {
            state.volumeVal = volumeVal
        },
        //保存歌曲时长秒数
        savemaxTime(state, maxTime) {
            state.maxTime = maxTime
        },
        //保存当前播放模式
        savePlayOrder(state, playOrder) {
            state.playOrder = playOrder
        },

    },

    actions: {
        //保存islike
        saveIsLike({
            commit
        }, payload) {
            commit('saveIsLike', payload);
        },
        //保存列表索引
        saveListIndex({
            commit
        }, payload) {
            commit('saveListIndex', payload);
        },
        //保存歌词开关
        saveIsOnPlay({
            commit
        }, payload) {
            commit('saveIsOnPlay', payload);
        },
        // 保存播放状态
        saveIsPlaying({
            commit
        }, payload) {
            commit('saveIsPlaying', payload);
        },
        //保存当前播放列表
        savePlayList({
            commit
        }, payload) {
            commit('savePlayList', payload);
        },
        //添加到当前播放列表
        unshiftPlayList({
            commit
        }, payload) {
            commit('unshiftPlayList', payload)
        },
        pushPlayList({
            commit
        }, payload) {
            commit('pushPlayList', payload)
        },
        // 添加到历史记录播放列表
        unshiftHisMusicList({
            commit
        }, payload) {
            commit('unshiftHisMusicList', payload)
        },

        // 添加到播放过的歌曲歌单(避免上一首或者随机播放播放到重复的歌曲)
        pushHasPlayList({
            commit
        }, payload) {
            commit('pushHasPlayList', payload)
        },

        // 删除当前列表歌曲
        deletePlayListSong({
            commit
        }, payload) {
            commit('deletePlayListSong', payload)
        },

        // 删除历史列表歌曲
        deleteHisListSong({
            commit
        }, payload) {
            commit('deleteHisListSong', payload)
        },

        // 删除已经播放列表歌曲
        deleteHasListSong({
            commit
        }, payload) {
            commit('deleteHasListSong', payload)
        },

        // 清空歌单
        deleteAllList({
            commit
        }) {
            commit('deleteAllList')
        },
        // 播放所有歌曲
        playAllSong({
            commit
        }, payload) {
            commit('playAllSong', payload)
        },
        // 保存当前播放模式
        savePlayOrd({
            commit
        }, payload) {
            commit('savePlayOrd', payload)
        },
        // 保存当前正在播放的音乐路径
        saveMusicUrl({
            commit
        }, payload) {
            commit('saveMusicUrl', payload)
        },
        // 保存当前正在播放的音乐细节
        saveMusicDetail({
            commit
        }, payload) {
            commit('saveMusicDetail', payload)
        },
        // 保存当前正在播放的歌曲id
        saveSongId({
            commit
        }, payload) {
            commit('saveSongId', payload)
        },
        // 让播放过的歌曲等于当前歌单
        sameHasAndPlay({
            commit
        }) {
            commit('sameHasAndPlay')
        },
        // 保存当前搜索信息
        saveSearchInfo({
            commit
        }, payload) {
            commit('saveSearchInfo', payload)
        },
        // 改变当前加载状态
        changeIsLoading({
            commit
        }, payload) {
            commit('changeIsLoading', payload)
        },
        // 保存开始和结束时间
        saveAur({
            commit
        }, payload) {
            commit('saveAur', payload)
        },
        // 保存进度条当前进度
        saveNowDuration({
            commit
        }, payload) {
            commit('saveNowDuration', payload)
        },
        //保存播放过歌曲的id
        saveHasPlayList({
            commit
        }, payload) {
            commit('saveHasPlayList', payload)
        },
        //保存歌单id
        saveSongListId({
            commit
        }, payload) {
            commit('saveSongListId', payload)
        },
        //保存歌曲时长
        saveDurationTime({
            commit
        }, payload) {
            commit('saveDurationTime', payload)
        },
        //保存当前播放音量
        saveVolumeVal({
            commit
        }, payload) {
            commit('saveVolumeVal', payload)
        },
        //保存歌曲时长秒数
        savemaxTime({
            commit
        }, payload) {
            commit('savemaxTime', payload)
        },
    },
    getters: {
        isLike: state => state.isLike,

        //歌词开关
        isOnPlay: state => state.isOnPlay,
        // 播放状态
        isPlaying: state => state.isPlaying,

        // 当前播放列表
        playList: state => state.playList,

        //当前歌单id
        songListId: state => state.songListId,

        // 历史播放列表
        hisMusicList: state => state.hisMusicList,

        // 播放过的歌曲歌单(避免上一首或者随机播放播放到重复的歌曲)
        hasPlayList: state => state.hasPlayList,

        // 当前播放模式
        playOrder: state => state.playOrder,

        // 当前播放歌曲url
        musicUrl: state => state.musicUrl,

        // 当前播放歌曲细节
        musicDetail: state => state.musicDetail,

        // 当前播放歌曲id
        songId: state => state.songId,

        // 当前进度条
        nowDuration: state => state.nowDuration,

        // 当前搜索信息
        searchInfo: state => state.searchInfo,

        // 当前加载状态
        isLoading: state => state.isLoading,

        // 开始和结束时间段
        slider: state => state.slider,
        playDur: state => state.playDur,

        // 搜索历史
        searchHistory: state => state.searchHistory,
        //歌曲时长
        durationTime: state => state.durationTime,
        //当前播放音量
        volumeVal: state => state.volumeVal,
        //歌曲时长秒数
        maxTime: state => state.maxTime,
        //歌曲当前时长
        currentTime: state => state.currentTime,
        //歌曲当前原始秒数
        sliderTime: state => state.sliderTime,
        //列表索引
        listIndex: state => state.listIndex


    }
}